package router

import (
	"gadmin/controller"

	"github.com/gin-gonic/gin"
)

func BuildRouter() (router *gin.Engine) {
	router = gin.Default()

	// 添加认证中间件
	auth := AddJWTMiddleware(router)
	{

		auth.GET("/", controller.Index)
		auth.GET("/menu", controller.GetMenu)

		auth.GET("/table", controller.GetTable)
		auth.POST("/table", controller.CreateTable)
		auth.DELETE("/table", controller.DeleteTable)
		auth.POST("/column", controller.CreateColumn)

		auth.GET("/datasource", controller.GetDatasource)
		auth.POST("/datasource", controller.CreateDatasource)
		auth.DELETE("/datasource", controller.DeleteDatasource)
		auth.GET("/data", controller.PreviewDatasource)
		// router.PUT("/api/bookmark", controller.SyncBookmark)

		auth.GET("/workflow", controller.GetWorkflow)             // 获取工作流
		auth.POST("/workflow", controller.CreateOrUpdateWorkflow) // 创建工作流
		auth.PUT("/workflow", controller.CreateOrUpdateWorkflow)
		auth.POST("/run", controller.RunWorkflow)           // 执行工作流
		auth.GET("/history", controller.GetWorkflowHistory) // 获取工作流的执行历史
	}

	return router
}
